package org.aplikator.server.data;

import java.io.InputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 *   Wrapper class for holding binary data (byte array) and corresponding properties.
 *   Provides also convenience constructors for initialization of the properties based on the filename.
 */
public class BinaryData implements Serializable {
    private static final long serialVersionUID = 3328753266953957306L;

    /**
     * Property key for filename
     */
    public static final String FILENAME_KEY = "filename";


    /**
     *  Binary data placeholder - provide inputStream and size of the data
     */
    public InputStream inputStream;
    public long dataLength;

    /**
     * Properties placeholder, initialized upon instance creation
     */
    public Map<String,String> properties = new HashMap<String,String>();

    /**
     * Default constructor
     */
    public BinaryData(){}

    /**
     * Convenience constructor, adds the filename to the field properties
     */
    public BinaryData(String filename){
        properties.put(FILENAME_KEY,filename);
    }


    /**
     *  Convenience constructor, adds the filename to the field properties and sets the temporaryFile field.
     */
    public BinaryData(String filename, InputStream inputStream, long dataLength){
        this(filename);
        this.inputStream = inputStream;
        this.dataLength = dataLength;
    }
}
